package com.stefanini.pe.bbva.iivs.in.utils;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class ConexionReporte {

	public static synchronized Connection getConnection() throws SQLException {
		/* DESARROLLO - TEST - PROD */
		try {
			Hashtable env = new Hashtable();
			env.put(Context.INITIAL_CONTEXT_FACTORY,
					"com.ibm.websphere.naming.WsnInitialContextFactory");
			InitialContext ctx = new InitialContext(env);
			DataSource ds = (DataSource) ctx.lookup("jdbc/IIGM");
			return ds.getConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static void close(Connection conn) {
		try {
			if (conn != null)
				conn.close();
		} catch (Exception sqle) {
			sqle.printStackTrace();
		}
	}

	public static void close(PreparedStatement stmt) {
		try {
			if (stmt != null)
				stmt.close();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
	}
	public static void close(CallableStatement cs) {
		try {
			if (cs != null) {
				cs.clearParameters();
				cs.close();
			}
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
	}
	public static void close(ResultSet rs) {
		try {
			if (rs != null)
				rs.close();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
	}

}
